package com.example.springdate.dto;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import com.example.springdate.domain.Users;
/**
 * 接口相当于
 * @RepositoryDefinition(domainClass = AccountInfo.class, idClass = Long.class) 
 public interface UserDao { …… }
 * */

public interface UserDao extends CrudRepository<Users, String>{
	@Query("select u from Users u where u.id=?1")
	public Users getByid(String id);
	@Query("select u from Users u where u.id=:id")
	public Users getByprimarykey(@Param("id")String id);
	/**
	 * @Query 的同时，用 @Modifying 来将该操作标识为修改查询，这样框架最终会生成一个更新的操作，而非查询。如下所示：
	 * */
	@Modifying
    @Query("update Users u set u.username=:username where u.id=:id")
	public void updateByid(@Param("id")String id,@Param("username")String username);
}
